<?php

namespace app\common\model;

use think\Model;


class Topic extends Model
{
    // 表名
    protected $name = 'topic';


    public function getCreatetimeAttr($value)
    {
        $status = date('Y-m-d', $value);
        return $status;
    }



    //根据分类ID获取指定数据
    public static function getList($data)
    {
        $info=self::where(function ($query)  {
            $query->where('status', '=', 'normal');
            $query->where('is_home_show', '=', 1);
        })->order(['weigh'=>'desc','createtime'=>'desc']);

        if(!empty($data['keywords'])){
            $info->where('title','like','%'.$data['keywords'].'%');
        }
        $list=$info->field('id,title,createtime,image')->order(['weigh'=>'desc','createtime'=>'desc'])->paginate(15,false,['page'=>$data['page']]);
        return $list;
    }


    /*
    * 读取分页
    * @param string $type   指定类型
    * @param string $status 指定状态
    * @return array
    */
    public static function details($id)
    {

        $list=self::where(['id'=>$id,'status'=>'normal'])->find();
        $list->setInc('show_number',1);
        return $list;
    }


}
